package dao.Impl;


import dao.TuserAddressDao;
import pojo.TuserAddress;
import util.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TuserAddressDaoImpl extends BaseDao implements TuserAddressDao {


    @Override
    public List<TuserAddress> selById(int id) {
        String sql = "select * from t_user_address where user_id = ? ";
        rs = exeQ(sql,id);
        List<TuserAddress> list = new ArrayList<>();
        TuserAddress ts = null;
        try {
            while (rs.next()) {
                ts = new TuserAddress(rs.getInt(1),
                        rs.getInt(2),
                        rs.getString(3),
                        rs.getString(4),
                        rs.getString(5),
                        rs.getString(6));
                list.add(ts);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public void address(TuserAddress ta) {
        String sql = "insert into t_user_address (user_id, address, create_time, is_default, remark)\n" +
                "values (?,?,now(),0,?)";
        exeU(sql,ta.getUserId(),ta.getAddress(),ta.getRemark());
    }
}
